package com.zdkj.subway.check.controller.subwayRat.TVMRevenueVarianceAudit.TvmChaYiDXC.tvmCengJiCYXC.tvmXianJinCengJiCYDXC;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;

/**
 * 互联网售票机下载
 */
@Controller
@RequestMapping("/check")
@Slf4j
public class HulianShouPiaoJiDownController {

    /**
     * 下载
     * @param req
     * @param res
     * @throws IOException
     */
    @RequestMapping("/down_hlw_upload_Templete")
    @ApiOperation(value = "下载", notes = "下载")
    public void down_hlw_upload_Templete(HttpServletRequest req, HttpServletResponse res) throws IOException {
        res.setCharacterEncoding("utf-8");
        res.setContentType("application/vnd.ms-excel");
        res.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("hlw_spj_tm.xls", "utf-8"));
        ServletOutputStream outputStream = res.getOutputStream();
        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("file/hlw_spj_tm.xls");
        int b = 0;
        byte[] buffer = new byte[1024];
        while ((b = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, b);
        }
        //流关闭
        inputStream.close();
        outputStream.close();
    }


}
